package com.xit.hitmouse.ui;

//import com.example.hitmouse.R;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.CycleInterpolator;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.core.content.ContextCompat;

import com.xit.hitmouse.R;
import com.xit.hitmouse.utils.ConvertUtils;
import com.xit.hitmouse.utils.CustomAnimation;

import java.util.Random;

/**
 * @author 厦工 友敏612
 * @Date 2023/11/20
 */
public class DiffityActivity extends Activity implements OnClickListener {
	Button easy;
	Button medium;
	Button backFirst;
	Button difficult;
	Button easy1;
	Button medium1;
	Button difficult1;

	Button btnLeft;
	Button btnRight;

	Button shopbtn;

	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.diffity_layout);
        easy = (Button) findViewById(R.id.easy);
        medium = (Button) findViewById(R.id.medium);
        difficult = (Button) findViewById(R.id.difficult);
		backFirst=findViewById(R.id.backFirst);

		shopbtn=findViewById(R.id.shopbtn);
        easy.setOnClickListener(this);
        medium.setOnClickListener(this);
        difficult.setOnClickListener(this);
		backFirst.setOnClickListener(this);
		shopbtn.setOnClickListener(this);

		initChange();
		//商城的动画效果
 		CustomAnimation.shopAnimation(shopbtn);
        }

	@Override
	public void onClick(View view) {
		Intent intent = new Intent(DiffityActivity.this, HitActivity.class);
		 //我这个版本使用 switch 函数   会出问题  说case的表达式不支持
		if (view.getId() == R.id.easy) {
			intent.putExtra("maptype","1");//地图类型
			startActivity(intent);
		}else if (view.getId() == R.id.medium) {
			intent.putExtra("maptype","2");//地图类型
			startActivity(intent);
		} else if (view.getId() == R.id.difficult) {
			intent.putExtra("maptype","3");//地图类型
			startActivity(intent);
		}else if (view.getId() == R.id.backFirst){
			finish();
		}else if(view.getId() == R.id.shopbtn){
			Intent intent2 = new Intent(DiffityActivity.this, ShopActivity.class);
			startActivity(intent2);
		}


	}

 private  void initChange(){
	 easy1 = findViewById(R.id.easy1);
	 medium1 = findViewById(R.id.medium1);
	 difficult1 = findViewById(R.id.difficult1);
	 btnLeft=findViewById(R.id.change_btn);
	 btnRight=findViewById(R.id.change_btn2);

	 int[] imageResources = { R.drawable.c11, R.drawable.c22, R.drawable.c33 };
	 int[] imageResources2 = { R.drawable.c1, R.drawable.c2, R.drawable.c3 };



	 Button[] imageViews = new Button[3];
	 imageViews[0] = easy1;
	 imageViews[1] = medium1;
	 imageViews[2] = difficult1;

	 Button[] imageViews2 = new Button[3];
	 imageViews2[0] = easy;
	 imageViews2[1] = medium;
	 imageViews2[2] = difficult;


	 btnLeft.setOnClickListener(new View.OnClickListener() {
		 @Override
		 public void onClick(View v) {

			 changeImage(imageResources , imageViews ,1);
			 changeImage(imageResources2 , imageViews2 ,1);
		 }
	 });

	 btnRight.setOnClickListener(new View.OnClickListener() {
		 @Override
		 public void onClick(View v) {

			 changeImage(imageResources , imageViews ,2);
			 changeImage(imageResources2 , imageViews2 ,2);
		 }
	 });

 }
	private  void changeImage(int[] imageResources , Button[] imageViews , int type){

		// 存储初始位置的数组
		float[] initialX = new float[imageViews.length];
		float[] initialY = new float[imageViews.length];


		for (int i = 0; i < imageViews.length; i++) {
			initialX[i] = imageViews[i].getX();
			initialY[i] = imageViews[i].getY();
		}
		// 创建并启动图案移动的动画
		for (int i = 0; i < imageViews.length; i++) {
			int nextIndex;
			if (type == 1) {  //例如向左移动 第一个是0 然后 i+1 是 1 nextIndex = 1  就是吧移到1
				nextIndex = (i + 1) % imageViews.length;
			} else {
				nextIndex = (i - 1 + imageViews.length) % imageViews.length;
			}
			CustomAnimation.moveImage(imageViews[i], initialX[nextIndex], initialY[nextIndex],500);
		}

	}


}
